--*****************************参数设置**********************************--
local pos={10,20,30} 
local Count = 10

local ZAxisParam = {
    Unit = 10000, --脉冲当量
    Speed = 1000, --速度
    Acc = 0.01,   --加速度
    Dec = 0.01,   --减速度
    S = 0.1,      --S曲线
}
--*****************************参数设置**********************************--

Cia402Device = ImportModel("Cia402DeviceBase")
local Sensor= ImportModel("SensorBase")
local file = ImportModel("FileBase")
file.IsPrint = true
local path = file.OpenFileDialog()
if path == nil then
    print("未选择保存目录")
    return
end
print(path)

local card = CardMaster
local jodell = Cia402Device.Init(card,"Jodell")
Sensor.PosPort = "COM8"
Sensor.PosBaud = 38400

jodell.AxisId = 0

card:Init()
Delay(5000)
jodell:OpenCia402()
jodell:ClearAxisError()
local xx, nums = card:GetAxisNums(0)
if nums == 0 then
    print("未扫描到轴")
    return
end

jodell:Enable(true)
Delay(2000)
jodell:SetProFile(ZAxisParam.Unit, ZAxisParam.Speed, ZAxisParam.Acc, ZAxisParam.Dec, ZAxisParam.S)
jodell:Move(0, true)

for i, v in ipairs(pos) do
    for y = 1, Count, 1 do
        jodell:Move(0, true)
        Delay(500)
        local startPos = Sensor.GetPos()
        jodell:Move(v, true)
        Delay(500)
        local stopPos = Sensor.GetPos()
        local str =string.format("次数,%d,目标位置,%.2f,开始位置,%.3f,结束位置,%.3f", y, v, startPos, stopPos)
        file.write_file(path,str)
    end
end

jodell:Move(0,true)
